<?php
namespace app\api\model;

class Robotnfc extends Base
{
    //机器人

    /**
     * 卡详情
     */
    public function cardOne($serial)
    {
        $res = $this->dbConn($this->dbStoreCard)
            ->where(['serial' => $serial])
            ->find();
        if (!$res) {
            return $this->toback(-2, '没有记录');
        }
        if (!$res['uid']) {
            return $this->toback(-2, '这是空卡');
        }
        $res['amount'] = round(($res['amount'] / 100), 2);
        //读取用户信息
        $uOne = $this->dbConn($this->dbUser)->where('user_id', $res['uid'])->find();
        if (!$uOne) {
            return $this->toback(-2, '用户错误');
        }
        return $this->toback(0, '', $res);
    }

    //开门
    public function doorOpen($doorno)
    {
        $res = $this->dbConn($this->dbShdDoor)
            ->where('del', 0)
            ->where('door_no', $doorno)
            ->find();
        if (!$res) {
            return $this->toback(-2, '没有设备');
        }
        $up = $this->dbConn($this->dbShdDoor)
            ->where('id', $res['id'])
            ->update(['status' => 2, 'opentime' => $this->toDate()]);
        if (!$up) {
            return $this->toback(-1, 'fail');
        }
        return $this->toback();
    }
}